/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package group2assignone.ucm.manager;

import group2assignone.dao.MyDAO;
import group2assignone.model.Flight;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.manager.AddPromotionView;

/**
 * Use Case: Confirm add new airport                                        <br>
 * Pre-condition: User clicks search in the add promotion view             .<br>
 * Post-condition: promotion view is updated to show flight                 <br>
 * 1. system retrieves flight from database                                 <br>
 * 2. System dispalys promotion view with flight details                    <br>

 *      1 a) searched Flight number does not exist                          <br>
 *              - display error
 *              - format fields                                             <br>
 *                                                                           <br>
 * @author group2
 */
public class UCAddPromotionSearch implements UCController{


    private AddPromotionView promoView = new AddPromotionView();
    private Flight f;// = new Flight();

    /**
     * sets view and flight
     * @param eView
     * @param fl
     */
    public UCAddPromotionSearch(AddPromotionView pView, Flight fl) {
        promoView = pView;
        f = fl;
    }

    @Override
    public void run() {
        // 1. system retrieves flight from database
        MyDAO coms = UCStartup.getInstance().getDAO();
        f = coms.sQLGetFlight(promoView.getFlightNum());

        System.out.println("in UCAddPromotionSEarch. got flight " + f.getFlightNum());
        if (f.getFlightNum().equals(null)) //if flight doesn't exist
        {
             //1 a) searched Flight number does not exist
             //  - display error
             //  - format fields
            promoView.resetFlightNum();
            promoView.errorFlightNum(); //show error message
        } else {
            //System dispalys promotion view with flight details
            promoView.showFlightDetails(f); //else display details
        }

    }


}
